﻿using DosTexPrj.Core.Models;
using FluentNHibernate.Mapping;

namespace DosTexPrj.Implement.NHibernate.Mapping
{
    public class SupplierMapping : ClassMap<Supplier>
    {
        public SupplierMapping()
        {
            Table("Suppliers");
            Id(x => x.Id, "SupplierID").UnsavedValue(0).GeneratedBy.Identity();
            Map(x => x.SupplierName, "SupplierName").Not.Nullable().Length(100);
            Map(X => X.Address, "Address").Not.Nullable().Length(200);
            Map(x => x.Phone, "Phone").Not.Nullable().Length(20);
            HasMany<YarnOrder>(x => x.YarnOrders).KeyColumn("SupplierID")
                                                .Cascade.All()
                                                .Not.LazyLoad().AsBag();
        }
    }
}